 import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class NewsReaderFrame {
    
    public JTextArea text1;
    public JTextArea text2;
    
    NewsReaderFrame(){
        JPanel textPanel = new JPanel();
        text1 = new JTextArea(30,30);
        JScrollPane scrollPane1 = new JScrollPane(text1, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        
        text2 = new JTextArea(30,50);
        JScrollPane scrollPane2 = new JScrollPane(text2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
 
        textPanel.add(scrollPane1);
        textPanel.add(scrollPane2);
        
        JPanel buttonPanel = new JPanel();
         buttonPanel.setLayout(new GridLayout(1,1));
        JButton button = new JButton("Read News");
        button.addActionListener(this.new NewsReaderButtonAction());
        
        buttonPanel.add(button);
        
        JPanel panel = new JPanel();
        panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS));
        
        panel.add(textPanel);
        panel.add(buttonPanel);
        
        JFrame frame = new JFrame("Lesson21: File Reader With SwingWorker");
        
        frame.setContentPane(panel);
        frame.setLocation(100,50);
        frame.setVisible(true);
        frame.pack();
    }
    
    public static void main(String[] args){
                
        NewsReaderFrame nrf = new NewsReaderFrame();
                                
    }
    
    class NewsReaderButtonAction implements ActionListener{
        
        public void actionPerformed(ActionEvent e){
            
            System.out.println("Read News: Button Pressed");
            
            File file1 = new File("C:\\Users\\Cristina\\Documents\\raspuns.txt");
            File file2 = new File("C:\\Users\\Cristina\\Documents\\ResearchStatement.tex");
            
            NewsReader nr1 = new NewsReader(file1, text1);
            NewsReader nr2 = new NewsReader(file2, text2);
 
            nr1.execute();
            nr2.execute();

    }
    }    
}

